<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        云客客户关系管理系统
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/css/x-admin.css" media="all">
</head>

<div class="x-body">
    <form class="layui-form">
    <div class="layui-form-item">
        <label for="userName" class="layui-form-label">
            用户名称
        </label>
        <div class="layui-input-inline">
            <input type="text" id="userName" name="userName" required="" lay-verify="required"
                   autocomplete="off" class="layui-input" value="${user.name}">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="oldPassword" class="layui-form-label">
            旧密码
        </label>
        <div class="layui-input-inline">
            <input type="password" id="oldPassword"  name="password" required="" lay-verify="pass"
                   autocomplete="off" class="layui-input" value="${user.password}" >
        </div>
        <div class="layui-form-mid layui-word-aux">
            6到16个字符
        </div>
    </div>
    <div class="layui-form-item">
        <label for="newPassword" class="layui-form-label">
            <span class="x-red">*</span>新密码
        </label>
        <div class="layui-input-inline">
            <input type="password" id="newPassword" name="repass" required="" lay-verify="repass"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="L_sign" class="layui-form-label">
        </label>
        <button class="layui-btn" key="set-mine" lay-filter="save" lay-submit>
            保存
        </button>
    </div>
    </form>
</div>
</body>
<script src="/static/lib/layui/layui.js" charset="utf-8">
</script>
<script src="/static/js/x-layui.js" charset="utf-8">
</script>
<script>
    layui.use(['form','layer'], function() {
        $ = layui.jquery;
        var form = layui.form()
                , layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename: function (value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            }
            , pass: [/(.+){6,12}$/, '密码必须6到12位']
            , repass: function (value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });
        var app=0;
        form.on('submit(save)', function () {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/user/editPassword",
                data: {
                    userName: $("#userName").val(),
                    oldPassword: $("#oldPassword").val(),
                    newPassword: $("#newPassword").val(),
                },
                success: function (msg) {
                    app=msg.data;
                    alert(app);
                }
            });

            if(app<0){
                layer.alert("密码修改失败", {icon: 6}, function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
            }else{
                layer.alert("密码修改成功", {icon: 6}, function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
            }
            return false;

        })
    })
</script>
</html>